﻿using Bsznq.Repositories.SqlConnections;
using Dapper;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bsznq.Repositories
{
    public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity : class
    {

        public string ConnectionString { get; set; }
        public IDbConnection DBConnection { get; set; }

        public RepositoryBase(SqlConnectionBase dbConnection)
        {
            DBConnection = dbConnection.DBConnection;
            ConnectionString = dbConnection.ConnectionString;
        }

        public virtual bool Insert(TEntity t)
        {
            throw new NotImplementedException();
        }

        public virtual bool Insert(List<TEntity> t)
        {
            throw new NotImplementedException();
        }

        public virtual bool Delete(object id)
        {
            throw new NotImplementedException();
        }

        public virtual bool Delete(string sql, object parameters = null)
        {
            throw new NotImplementedException();
        }

        public virtual bool Delete(List<TEntity> list)
        {
            throw new NotImplementedException();
        }

        public virtual bool Update(TEntity t)
        {
            throw new NotImplementedException();
        }

        public virtual bool Update(List<TEntity> t)
        {
            throw new NotImplementedException();
        }

        public virtual TEntity SelectById(object id)
        {
            throw new NotImplementedException();
        }

        public virtual List<TEntity> SelectList(string sql, object parameters = null)
        {
            throw new NotImplementedException();
        }

        public virtual List<TEntity> SelectAll()
        {
            throw new NotImplementedException();
        }

        public bool Execute(string sql, object parameters = null)
        {
            using (IDbConnection _db = new SqlConnection(ConnectionString))
            {
                int rowsAffected = _db.Execute(sql, parameters);
                return rowsAffected > 0;
            }
        }

        public T Select<T>(string sql, object parameters = null)
        {
            using (IDbConnection _db = new SqlConnection(ConnectionString))
            {
                T data = _db.Query<T>(sql, parameters).FirstOrDefault();
                return data;
            }
        }

        public virtual TEntity Select(string sql, object parameters = null)
        {
            throw new NotImplementedException();
        }

    }
}
